package com.dzxcqmxm.Dao.impl.testServletContext;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 *在test1存数据,这里不用加映射因为web.xml要注册
 */
public class test1 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //ServletContext 上下文
        ServletContext context = this.getServletContext();
        //数据
        String username="小明";
        //将数据保存在ServletContext中，参数为键值对(名，对象）
        context.setAttribute("username",username);

    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
